package org.lanqiao.lg.dao.impl;

import java.util.List;
import java.util.Map;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;
import org.lanqiao.bean.Product;
import org.lanqiao.lg.dao.ProductDao;
import org.lanqiao.tools.BaseDao;

public class ProductDaoImpl extends BaseDao implements ProductDao {

//	@Override 通过产品id查询产品信息
	public Product selectProductById(Integer id) {
		try {
			return query.query("select * from product where id=?", new BeanHandler<Product>(Product.class), id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 添加产品
	public Integer insertProduct(Product info) {
		try {
			return query.update(
					"INSERT INTO product(name,com,introduction,imgId,companyId,stateId,date) VALUES(?,?,?,?,?,1,NOW())",
					info.getName(), info.getCom(), info.getIntroduction(), info.getImgId(),
					info.getCompanyId());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

//	@Override 通过公司id查询产品 只查询最新的两个
	public List<Map<String, Object>> selectProductByCId(Integer cid) {
		try {
			return query.query("select * from product where companyid=? ORDER BY date DESC LIMIT 0,2", new MapListHandler(),cid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
